package com.fanbuchi.fukua.api;

import com.squareup.okhttp.Callback;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;

/**
 * Created by Administrator on 2015/7/2.
 */
public class MsgesAPI extends API{
    public static final MediaType mediaType = MediaType.parse("application/json;charset=utf-8");
    private  final static String msgUri=getHost()+"/msg";
    private  final static String publicMsg=msgUri+"/publicMsg";
    private  final static String getMsgsByPage=msgUri+"/getMsgsByPage";


    public static MsgesAPI API;

    private  MsgesAPI(){
    }
    public static MsgesAPI getAPI(){
        if (API==null){
            API = new MsgesAPI();
        }
        return API;
    }

    public  void publicMsg(String json,Callback callback) {
        RequestBody body = RequestBody.create(mediaType, json);
        Request request = new Request.Builder()
                .url(publicMsg)
                .headers(getNormalHeaders())
                .post(body)
                .build();
        mClient.newCall(request).enqueue(callback);
    }

    public  void getMsgsByPage(int page,int pageSize,Callback callback) {
        Request request = new Request.Builder()
                .url(getMsgsByPage+"?page="+page+"&page_size="+pageSize)
                .headers(getNormalHeaders())
                .build();
        mClient.newCall(request).enqueue(callback);
    }

}
